import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/components/easy_toast.dart';
import 'package:pornhub_app/generate/app_image_path.dart';
import 'package:pornhub_app/services/user_service.dart';
import 'package:pornhub_app/views/mine/frontpage/controller/edit_userinfo_controller.dart';

class SystemAvatorPageController extends GetxController {
  final List<String> avatorList = [
    AppImagePath.mine_img_avator1,
    AppImagePath.mine_img_avator2,
    AppImagePath.mine_img_avator3,
    AppImagePath.mine_img_avator4,
    AppImagePath.mine_img_avator5,
    AppImagePath.mine_img_avator6,
    AppImagePath.mine_img_avator7,
    AppImagePath.mine_img_avator8,
    AppImagePath.mine_img_avator9,
    AppImagePath.mine_img_avator10,
    AppImagePath.mine_img_avator11,
    AppImagePath.mine_img_avator12,
    AppImagePath.mine_img_avator13,
    AppImagePath.mine_img_avator14,
    AppImagePath.mine_img_avator15,
    AppImagePath.mine_img_avator16,
    AppImagePath.mine_img_avator17,
    AppImagePath.mine_img_avator18,
    AppImagePath.mine_img_avator19,
    AppImagePath.mine_img_avator20,
    AppImagePath.mine_img_avator21,
    AppImagePath.mine_img_avator22,
    AppImagePath.mine_img_avator23,
    AppImagePath.mine_img_avator24,
    AppImagePath.mine_img_avator25,
    AppImagePath.mine_img_avator26,
    AppImagePath.mine_img_avator27,
    AppImagePath.mine_img_avator28,
    AppImagePath.mine_img_avator29,
    AppImagePath.mine_img_avator30,
    AppImagePath.mine_img_avator31,
    AppImagePath.mine_img_avator32
  ];

  final us = Get.find<UserService>();
  var systemAvator = "".obs;
  final controllerEditUser = Get.find<EditUserInfoController>();

  checkAvator(int index) {
    systemAvator.value = avatorList[index];
  }

  uploadAvator() async {
    if (systemAvator.value.isEmpty) {
      EasyToast.show("请选择头像");
      return;
    }
    ByteData byteData = await rootBundle.load(systemAvator.value);
    Uint8List bytes = byteData.buffer.asUint8List();
    controllerEditUser.postUploadImg(bytes);
  }
}
